<template>
        <el-dialog  :title="title" modal="true"  :fullscreen="fullscreen" center="true" destroy-on-close="true" v-model="showSysCompanyEdit" >
            <el-form :model="formObj" :rules="rules" ref="formSysCompanyEdit">
                <el-form-item prop="name" label="企业名称" :label-width="formLabelWidth">
                    <el-input v-model="formObj.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="法人" :label-width="formLabelWidth">
                    <el-input v-model="formObj.legalPerson" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="统一社会信用代码" :label-width="formLabelWidth">
                    <el-input v-model="formObj.creditCode" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="公司类型" :label-width="formLabelWidth">
                    <el-input v-model="formObj.companyType" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="经营状态" :label-width="formLabelWidth">
                    <el-input v-model="formObj.manageStatus" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="成立日期" :label-width="formLabelWidth">
                    <el-input v-model="formObj.createTime" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="工商注册号" :label-width="formLabelWidth">
                    <el-input v-model="formObj.regCode" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="注册地址" :label-width="formLabelWidth">
                    <el-input v-model="formObj.regAddress" autocomplete="off"></el-input>
                </el-form-item>

            </el-form>
            <template #footer>
                <span class="dialog-footer">
                     <el-button type="primary" @click="saveCompany()">保 存</el-button>
                     <el-button @click="showSysCompanyEdit = false">取 消</el-button>
                </span>
            </template>
        </el-dialog>

</template>

<script>
    import {clearObject, postReq, putReq} from "../../../utils/api";
    import { ElMessage } from 'element-plus'

    export default {
        name: "SysMenuEdit",
        components:{},
        data(){
            return{
                formObj:{
                    id:'',
                    name:undefined,
                    legalPerson:undefined,
                    creditCode:undefined,
                    companyType:undefined,
                    manageStatus:undefined,
                    createTime:undefined,
                    regCode:undefined,
                    regAddress:undefined,
                },
                showSysCompanyEdit:false,
                title:'',
                formLabelWidth: '150px',
                fullscreen:false,
                rules:{
                    name: [
                        { required: true, message: '请填写企业名称', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请填写用户名密码', trigger: 'blur' }
                    ]
                }
            }
        },
        methods:{
            open(formObj){
                if (formObj){
                    this.formObj = formObj
                }else {
                    clearObject(this.formObj)
                }
                this.showSysCompanyEdit=true
            },
            saveCompany(){
                this.$refs['formSysCompanyEdit'].validate((valid) => {
                    if (valid) {
                        if (this.formObj.id){
                            //编辑
                            putReq('/api/sys_company/'+this.formObj.id,this.formObj).then(res=>{
                                this.$emit('page')
                                this.showSysCompanyEdit=false
                                ElMessage.success({
                                    message: '编辑成功！',
                                    type: 'success'
                                });
                            })
                        }else {
                            //新增
                            postReq('/api/sys_company/add',this.formObj).then(res=>{
                                if (res){
                                    this.$emit('page')
                                    this.showSysCompanyEdit=false
                                    ElMessage.success({
                                        message: '编辑成功！',
                                        type: 'success'
                                    });
                                }

                            })
                        }
                    } else {
                        return false;
                    }
                });
            }
        }
    }
</script>

<style scoped>

</style>